|
|
 |
|
|
|
|
' Define the BITMAP data structure. Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
:
Dim bm As BITMAP
' Load the bm data structure with
' information about the bitmap. GetObjectAPI picCanvas.Image, Len(bm), bm |
|
|
|
|
|
|
|
|
The fields in the BITMAP data structure contain the following information about the bitmap. |
|
|
|
|
| | | |
|
|
|
|
The size of the bitmap in pixels |
|
|
|
| | |
|
|
|
|
How many bytes are in each scanline of the bitmap |
|
|
|
| | |
|
|
|
|
How many bits are used to represent each pixel's color value |
|
|
|
| | |
|
|
|
|
The number of color planes used by the bitmap |
|
|
|
| | |
|
|
|
|
An array of data representing the pixels' values |
|
|
|
|
|
|
|
|
|
|
The value bmWidthBytes is the product of bmBitsPixel and bmWidth rounded up to the nearest even number. When you deal directly with bitmap structures, it is important to remember the extra bytes added by this rounding. If you do not allow space for them, you program will probably crash, possibly bringing down the Visual Basic development environment with it. |
|
|
|
|
|
|
|
|
The GetObject function does not fill in the bmBits field for bitmaps. After you use GetObject to see how large the bitmap is, you can allocate an array to hold the pixel values and then get those values using the GetBitmapBits function. The following code shows the declaration of the GetBitmapBits function. |
|
|
|
 |
|
|
|
|
Private Declare Function GetBitmapBits Lib "gdi32" _
Alias "GetBitmapBits" (ByVal hBitmap As Long, _
ByVal dwCount As Long, lpBits As Any) As Long |
|
|
|
|
|
|
|
|
GetBitmapBits fills an array with the pixel values that make up a bitmap. Its dwCount parameter tells the function how many bytes it should copy into the array specified by lpBits. The bits are copied into the array one row at a time from top to bottom and left to right. |
|
|
|
|
|
|
|
|
The SetBitmapBits function does the opposite of GetBitmapBits. This function copies data from an array into a bitmap. The following code shows its declaration. |
|
|
|
|
|